package com.zp.security.oauth2.customized.config;

import com.zp.security.oauth2.customized.EmailAuthenticationProvider;
import com.zp.security.oauth2.customized.service.EmailCodeUserDetailService;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 电子邮件代码安全配置
 * 将EmailAuthenticationProvider配置到HttpSecurity
 *
 * @author zp
 * @date 2022/07/17
 */
@Component
public class EmailCodeSecurityConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain,HttpSecurity> {
    @Resource
    private PasswordEncoder passwordEncoder;
    @Resource
    private EmailCodeUserDetailService emailCodeUserDetailService;

    @Override
    public void configure(HttpSecurity builder) {
        //将EmailAuthenticationProvider注入
        EmailAuthenticationProvider emailAuthenticationProvider=new EmailAuthenticationProvider(emailCodeUserDetailService,passwordEncoder);
        builder.authenticationProvider(emailAuthenticationProvider);
    }

}
